
$(function () {
  $('#btn-login').on('click',function (params) {
 // 验证表单
  if(utils.validateEmpty('#email')){
    $('.container-fluid').text('邮箱不能为空');
    $('#modelId').modal();
    return;
  };
  let reg=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  if(!reg.test($('#email').val())){
    $('.container-fluid').text('邮箱格式不正确');
    $('#modelId').modal();
    return;
  };
  if(utils.validateEmpty('#password')){
    $('.container-fluid').text('密码不能为空');
    $('#modelId').modal();
    return;
  };  
  // 收集数据
let data = $('.login-wrap').serialize();
// console.log(data);
  // ajax提交
  $.ajax({
    type: "post",
    url: "/admin_do_login",
    data,
    success: function (res) {
      // console.log(res);
      let tip = null;
      if(res.code == 200){
        tip = '登陆成功';
        isSuccess = true;
      }else{
        tip = '登陆成功';
      };
      $('.container-fluid').text(tip);
      $('#modelId').modal();
    }
  });
   });
   let isSuccess = false;
  // 当模态框消失的时候,跳转
  $('#modelId').on('hidden.bs.modal',()=>{
    if(isSuccess){
      location.href = '/admin/index'
    }
  });


});